package com.shaobufan.museum.controllar;

import com.shaobufan.museum.common.BaseResponse;
import com.shaobufan.museum.common.ResultUtils;
import com.shaobufan.museum.pojo.request.collections.CollectionsAddRequest;
import com.shaobufan.museum.pojo.request.collections.CollectionsSearchRequest;
import com.shaobufan.museum.pojo.request.collections.CollectionsUpdateRequest;
import com.shaobufan.museum.pojo.vo.CollectionsVo;
import com.shaobufan.museum.service.CollectionsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import static com.shaobufan.museum.contant.CollectionsContent.*;

/**
 * 馆藏
 */
@RestController
@RequestMapping("/collections")
public class CollectionsController {
    @Resource
    CollectionsService collectionsService;

    @ApiOperation("查询馆藏")
    @PostMapping("/search")
    public BaseResponse<List<CollectionsVo>> searchCollections(@RequestBody CollectionsSearchRequest collectionsSearchRequest) {
        Integer collectionId = collectionsSearchRequest.getCollectionId();
        Integer categoryId = collectionsSearchRequest.getCategoryId();
        String collectionEra = collectionsSearchRequest.getCollectionEra();
        String collectionName = collectionsSearchRequest.getCollectionName();

        List<CollectionsVo> collectionsVoList = collectionsService.searchMuseumCollections(
                collectionId,
                categoryId,
                collectionEra,
                collectionName
        );
        return ResultUtils.success(collectionsVoList, CONFORM_COLLECTIONS_GET_SUCCESS);
    }

    /**
     * 插入馆藏
     *
     * @param collectionsAddRequest 添加馆藏请求体
     * @return 插入数据条数数据集
     */
    @ApiOperation("插入馆藏")
    @PostMapping("/insert")
    public BaseResponse<Integer> insertCollections(@RequestBody CollectionsAddRequest collectionsAddRequest) {
        Integer categoryId = collectionsAddRequest.getCategoryId();
        String collectionEra = collectionsAddRequest.getCollectionEra();
        String collectionDetail = collectionsAddRequest.getCollectionDetail();
        String collectionName = collectionsAddRequest.getCollectionName();
        String collectionImage = collectionsAddRequest.getCollectionImage();
        Integer result = collectionsService.insertMuseumCollection(categoryId, collectionEra, collectionDetail, collectionName, collectionImage);
        return ResultUtils.success(result, COLLECTIONS_GET_SUCCESS);
    }

    /**
     * 更新馆藏
     *
     * @param collectionsUpdateRequest 更新collections请求体
     * @return 更新数据条数数据集
     */
    @ApiOperation("更新馆藏")
    @PostMapping("/update")
    public BaseResponse<Integer> updateCollections(@RequestBody CollectionsUpdateRequest collectionsUpdateRequest) {
        Integer collectionId = collectionsUpdateRequest.getCollectionId();
        Integer categoryId = collectionsUpdateRequest.getCategoryId();
        String collectionEra = collectionsUpdateRequest.getCollectionEra();
        String collectionDetail = collectionsUpdateRequest.getCollectionDetail();
        String collectionName = collectionsUpdateRequest.getCollectionName();
        String collectionImage = collectionsUpdateRequest.getCollectionImage();

        Integer result = collectionsService.updateMuseumCollection(collectionId, categoryId, collectionEra, collectionDetail, collectionName, collectionImage);
        return ResultUtils.success(result, COLLECTIONS_UPDATE_SUCCESS);
    }

    @ApiOperation("删除馆藏")
    @DeleteMapping("/delete/{params}")
    public BaseResponse<Integer> deleteCollections(@PathVariable Integer params) {
        Integer i = collectionsService.deleteMuseumCollectionById(params);
        return ResultUtils.success(i, "成功删除");
    }
}